﻿using assignment2.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace assignment2.Entity
{
    public class Account
    {
        public string ID { get; set; }
        public string Password { get; set; }
        public double Balance { get; set; }
        public double Credit { get; }

        public Account() { }
        public Account(string id,string password,double balance)
        {
            ID = id;
            Password = password;
            Balance = balance;
        }

        public Account(double credit)
        {
            Credit = credit;
        }
        public double GetBalance()
        {
            return Balance;
        }
        public void Deposit(double amount)
        {
            if (amount <= 0)
            {
                throw new ArgumentException("存款金额必须大于0");
            }

            Random rand = new Random();
            if (rand.Next(100) < 30) // 模拟坏钞率为30%
            {
                throw new BadCashException("检测到坏钞票，请重新存款");
            }

            Balance += amount;

        }
        public virtual void Withdraw(double amount)
        {
            if (amount > 0 && amount <= Balance)
            {
                Balance -= amount;
            }
            else
            {
                throw new ArgumentException("取款金额必须大于0且不超过余额");
            }
        }
    }
}


    
